#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：图灵学习 
@File    ：12.重定向与历史请求.py
@IDE     ：PyCharm 
@Author  ：ChenLiGao
@Date    ：2024-11-20 11:14
'''
import requests

headers = {
    "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36",
}

url = "https://www.360buy.com"

# 可以通过allow_redirects来禁止跳转
response = requests.get(url, headers=headers, allow_redirects=False)

print(response.url)
print(response.history) # 返回一个响应列表，元素就是响应对象
for res in response.history:
    print(res.status_code, res.url)
    print(res.headers)
    print("-----------------" * 50)
